<?php
// 【最终完整版】profile.php

// 顶部的PHP验证逻辑被完全移除，只保留引入公共头部
require_once('common/header.php'); 
?>
<!-- 页面专属CSS -->
<style>
    .profile-header { padding: 25px 20px; background: linear-gradient(135deg, #4a69bd 0%, #1e3799 100%); color: white; }
    .profile-info { display: flex; align-items: center; }
    .profile-avatar { width: 64px; height: 64px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.7); object-fit: cover; }
    .profile-text { margin-left: 15px; text-align: left; }
    .profile-name { font-size: 1.25rem; font-weight: 600; margin: 0; }
    .profile-id { font-size: 0.8rem; opacity: 0.8; margin: 2px 0 0 0; }
    .balance-card { display: flex; text-align: center; background: rgba(255, 255, 255, 0.1); border-radius: 10px; padding: 15px; margin-top: 20px; }
    .balance-item { flex: 1; position: relative; }
    .balance-item:first-child::after { content: ''; position: absolute; right: 0; top: 10%; height: 80%; width: 1px; background-color: rgba(255,255,255,0.2); }
    .balance-item .label { font-size: 0.8rem; opacity: 0.8; }
    .balance-item .amount { font-size: 1.3rem; font-weight: 700; }
    .main-content { padding: 15px; }
    .list-group { border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.06); }
    .list-group-item { border-left: 0; border-right: 0; padding: 1rem; background-color: #fff; border-bottom: 1px solid #f0f0f0; }
    .list-group-item:last-child { border-bottom: none; }
    .list-group-item i.bi { font-size: 1.2rem; width: 24px; text-align: center; }
    .list-group-item.disabled-link { pointer-events: none; opacity: 0.65; }
</style>

<div id="profile-app" v-cloak>
    <div class="profile-header">
        <div class="profile-info">
            <img :src="profile.avatar" alt="avatar" class="profile-avatar">
            <div class="profile-text">
                <h2 class="profile-name">{{ profile.shop_name }}</h2>
                <p class="profile-id">代理ID: {{ profile.id }}</p>
            </div>
        </div>
        <div class="balance-card mt-4">
            <div class="balance-item">
                <div class="label">可提现金额</div>
                <div class="amount">￥{{ profile.available_balance }}</div>
            </div>
            <div class="balance-item">
                <div class="label">已提现金额</div>
                <div class="amount">￥{{ profile.withdrawn_balance }}</div>
            </div>
            <a href="#" class="btn btn-warning ms-3 align-self-center">立即提现</a>
        </div>
    </div>
    
    <div class="main-content">
        <!-- 数据统计卡片 -->
        <div class="row text-center mb-3 g-2">
            <div class="col"><div class="card card-body py-3"><h4 class="fw-bold mb-0">{{ profile.total_orders }}</h4><small class="text-muted">团队订单</small></div></div>
            <div class="col"><div class="card card-body py-3"><h4 class="fw-bold mb-0">{{ profile.sub_agents_count }}</h4><small class="text-muted">我的代理</small></div></div>
            <div class="col"><div class="card card-body py-3"><h4 class="fw-bold mb-0">{{ profile.active_rate }}%</h4><small class="text-muted">激活率</small></div></div>
        </div>

        <!-- 功能列表 -->
        <div class="list-group">
            <a href="agent.php" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center"><i class="bi bi-people-fill text-success"></i><span class="ms-3">代理管理</span></div>
                <i class="bi bi-chevron-right text-muted"></i>
            </a>
            <a href="commission.php" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center"><i class="bi bi-sliders text-primary"></i><span class="ms-3">全局佣金设置</span></div>
                <i class="bi bi-chevron-right text-muted"></i>
            </a>
        </div>
        
        <div class="list-group mt-3">
            <a :href="profile.is_renamed ? '#' : 'rename.php'" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center" :class="{ 'disabled-link': profile.is_renamed }">
                <div class="d-flex align-items-center"><i class="bi bi-person-badge-fill" :class="profile.is_renamed ? 'text-success' : 'text-danger'"></i><span class="ms-3">实名认证</span></div>
                <span v-if="profile.is_renamed" class="badge rounded-pill bg-light text-success border">已认证</span><i v-else class="bi bi-chevron-right text-muted"></i>
            </a>
            <a href="payout_account.php" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center"><i class="bi bi-cash-coin text-warning"></i><span class="ms-3">提现账户</span></div>
                <i class="bi bi-chevron-right text-muted"></i>
            </a>
            <a href="change_password.php" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center"><i class="bi bi-shield-lock text-secondary"></i><span class="ms-3">修改密码</span></div>
                <i class="bi bi-chevron-right text-muted"></i>
            </a>
        </div>
        
        <div class="p-3 mt-3">
             <button class="btn btn-danger w-100" @click="logout">退出登录</button>
        </div>
    </div>
</div>

<?php require_once('common/footer.php'); ?>